<template>
	<el-dialog title="选择默认带出分公司" :visible.sync="dialogVisible" size="small" :close-on-click-modal="false" :close-on-press-escape="false" :before-close="off">
		  <el-form label-width="150px" >
		  <el-row :span="24">
		  	<el-form-item label="默认带出分公司" label-width="150px" :span="24">
				<el-select v-model="arrayComcodes" multiple  placeholder="默认带出分公司" filterable size="small" style="width:80%">
					<el-option v-for="item in comOptions" :key="item.branchNo" :label="item.branchNo +  '-' + item.branchCname" :value="item.branchNo"></el-option>
				</el-select>
			</el-form-item>
		  </el-row>
		</el-form>
		  <span slot="footer" class="dialog-footer">
			   <el-button @click="off">取 消</el-button>
			   <el-button type="danger" @click="clear">清 空</el-button>
			   <el-button type="success" @click="select">确 定</el-button>
		  </span>
	</el-dialog>
</template>

<script>
import CompanyAPI from "../../../../js/production/company/companyAPI";
export default {
	data() {
		return {
			dialogVisible: true,
			arrayComcodes: [],
			comOptions: [],
		}
	},
	mounted() {
		let comLabel = this.$parent.comLabel;
		if (comLabel.indexOf("ALL") >= 0) {
			CompanyAPI.queryComs(this);
		} else {
      CompanyAPI.queryComsByCodes(this);
		}
		this.arrayComcodes = this.$parent.arrayDefaultCom;
	},
	methods: {
		select() {
			this.$parent.arrayDefaultCom = [];
			this.$parent.defaultComLabel = '';
			this.$parent.arrayDefaultCom = this.arrayComcodes;
			for(let i = 0; i <this.arrayComcodes.length - 1; i++) {
				this.$parent.defaultComLabel += this.arrayComcodes[i] + ",";
			}
			if(this.arrayComcodes.length > 0) {
				this.$parent.defaultComLabel += this.arrayComcodes[this.arrayComcodes.length - 1];
			}
			this.off();
		},
		clear() {
			this.arrayComcodes = [];
			this.$parent.arrayDefaultCom = [];
			this.$parent.defaultComLabel = '';
			this.off();
		},
		off() {
			this.$parent.showDefaultComSelectDialog = false;
		}
	}
  }
</script>
